package com.datastructures.tree;

import java.util.Stack;

/**
 * @author MaoLin Wang
 * @date 2020/2/1215:26
 */
public class Midb {


    public static void main(String[] args) {
        Stack<BinaryTree2>stack=new Stack<>();
        String s="ab+cde+**";
        BinaryTree2 node;
        for (int i = 0; i < s.length(); i++) {
            if (isOper(s.charAt(i))){
                node= new BinaryTree2(s.charAt(i));
                node.rchild=stack.pop();
                node.lchild=stack.pop();
                stack.push(node);
            }else {
                 node = new BinaryTree2(s.charAt(i));
                stack.push(node);
            }
        }
        System.out.println(stack.peek());
    }
    //判断是不是一个运算符
    public static boolean isOper(char val){
        return val == '+'||val=='-'||val=='*'||val=='/';
    }
}

class BinaryTree2{
    Object data;
    BinaryTree2 lchild;
    BinaryTree2 rchild;

    public BinaryTree2(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "BinaryTree2{" +
                "data=" + data +
                ", lchild=" + lchild +
                ", rchild=" + rchild +
                '}';
    }
}
